package Persistencia;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import Negocio.factura;
import Negocio.itemFactura;

public class admPersFactura {
	private static admPersFactura pool;
	private admPersFactura()
	{
		
	}
	public static admPersFactura getInstancia()
	{
		if (pool== null)
			pool =new admPersFactura();
		return pool;
	}	
	
	public void insert(factura F){
		Connection con = poolConnection.getPoolConnection().getConnection();
		String sentence = "INSERT INTO TBL_FACTURA (NRO, MES, ANIO) VALUES (?,?,?)";
		PreparedStatement ps = null;
		try {
			ps = con.prepareStatement(sentence);
			ps.setInt(1, F.getNumero());
			ps.setInt(2, F.getMes());
			ps.setInt(3, F.getAnio());
			ps.execute();
			poolConnection.getPoolConnection().realeaseConnection(con);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}

	public void insertItem(factura F, itemFactura i){
		Connection con = poolConnection.getPoolConnection().getConnection();
		String sentence = "INSERT INTO TBL_ITEMFACTURA (NRO, ITEM, CANTIDAD) VALUES (?,?,?)";
		PreparedStatement ps = null;
		try {
			ps = con.prepareStatement(sentence);
			ps.setInt(1, F.getNumero());
			ps.setInt(2, i.getProducto().getCodigo());
			ps.setInt(3, i.getCantidad());
			ps.execute();
			poolConnection.getPoolConnection().realeaseConnection(con);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}

}
